package com.hfb.mashibing.alip8.spring;

import com.hfb.mashibing.alip8.spring.component.MyFilter;
import com.hfb.mashibing.alip8.spring.component.MyHttpSessionListener;
import com.hfb.mashibing.alip8.spring.component.MyServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

@ServletComponentScan
@SpringBootApplication(scanBasePackages = {"com.hfb.mashibing.alip8.spring"})
@ConfigurationPropertiesScan
@EnableConfigurationProperties
//@MapperScan(basePackages="com.hfb.mashibing.alip8.spring.mapper")
//禁用spring自动配置数据库
//@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class SpringbootStudyApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootStudyApplication.class);
    }

    @Bean
    public ServletRegistrationBean<MyServlet> getServletRegistrationBean() {
        ServletRegistrationBean<MyServlet> bean =
                                                new ServletRegistrationBean<>(
                                                    new MyServlet(), "/s2");
        bean.setLoadOnStartup(1);

        return bean;
    }
    @Bean
    public FilterRegistrationBean<MyFilter> getFilterRegistrationBean() {
        FilterRegistrationBean<MyFilter> bean =
                                                new FilterRegistrationBean<>(
                                                    new MyFilter());

        return bean;
    }
    @Bean
    public ServletListenerRegistrationBean<MyHttpSessionListener> getServletListenerRegistrationBean() {
        ServletListenerRegistrationBean<MyHttpSessionListener> bean =
                                                new ServletListenerRegistrationBean<>(
                                                    new MyHttpSessionListener());

        return bean;
    }
}
